import { defineStore } from 'pinia';
import type { RouteRecordNormalized } from 'vue-router';
import { getStorage, setStorage } from '@/utils/tools'
import { initDiyData } from "@/api/common";
import { Result, ResultError } from '@/types';

export const configStore = defineStore({
    id: 'app-config',
    state: () => ({
        custom:{
            B:{
                right: 0,
                top: 0,
                height: 0,
                width: 0,
                left: 0,
            },
            H:0,
            statusH:0,
            capsuleH:0
        },
        DIYDATA: getStorage('DIYDATA'),
        DIYTHEME: getStorage('DIYTHEME'),
        DIYUSER:getStorage('DIYUSER'),
        DIYCATEGROY:getStorage('DIYCATEGROY'),
        payments:getStorage('PAYMENTS')
    }),
    actions: {
        setCustom(value: any) {
            this.$patch({
                custom:value
            })
        },
        async initDiyData() {
            const { data }: any = await initDiyData()
            this.setDiy(data);
            return data
        },
        setDiy(value:any) {
            if(value.page){
                setStorage('DIYDATA',value.page);
                this.$patch({
                    DIYDATA:value.page
                })
            }
            if(value.theme){
                setStorage('DIYTHEME',value.theme);
                this.$patch({
                    DIYTHEME:value.theme
                })
            }
            if(value.user){
                setStorage('DIYUSER',value.user);
                this.$patch({
                    DIYUSER:value.user
                })
            }
            if(value.categroy){
                setStorage('DIYCATEGROY',value.categroy);
                this.$patch({
                    DIYCATEGROY:value.categroy
                })
            }
            if(value.payment){
                setStorage('PAYMENTS',value.payment);
                this.$patch({
                    payments:value.payment
                })
            }
        },
    },
    getters: {
        getCustom(state): any {
            return state.custom
        },
        getDiyData(state): any {
            return state.DIYDATA
        },
        getDiyTheme(state): any {
            return state.DIYTHEME
        },
        getDiyUser(state): any {
            return state.DIYUSER
        },
        getDiyCategroy(state): any {
            return state.DIYCATEGROY
        },
        getPayments(state): any {
            return state.payments
        },
    }
})


export default configStore;